All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sun.servlet.http.HttpInputStream

java.lang.Object
   |
   +----java.io.InputStream
           |
           +----javax.servlet.ServletInputStream
                   |
                   +----sun.servlet.http.HttpInputStream

public class HttpInputStream
extends ServletInputStream
This class implements a buffered input stream for reading servlet request data. It also keeps track of the number of bytes that have been read, and allows the specification of an optional byte limit to ensure that the content length has not been exceeded.


Variable Index

 o buf
The input buffer.
 o count
The current number of bytes in the buffer.
 o in
The actual input stream for this request.
 o length
The content length for this request.
 o limit
The maximum number of bytes for the current request.
 o pos
The current position in the buffer.
 o total
The total number of bytes for the current request.

Constructor Index

 o HttpInputStream()
Creates a new, uninitialized input stream using a default buffer size.
 o HttpInputStream(int)
Creates a new, uninitialized input stream using the specified buffer size.

Method Index

 o available()
Returns the number of bytes that can be read without blocking.
 o close()
Closes the input stream.
 o fill()
Fills input buffer with more bytes.
 o finish()
Finishes reading the request without closing the underlying stream.
 o getContentLength()
Returns the content length for this input stream, or -1 if not set.
 o getTotal()
Returns the total number of bytes read so far.
 o init(InputStream)
Initializes the servlet input stream with the specified raw input stream.
 o next()
Begins reading the next request.
 o read()
Reads a byte of data.
 o read(byte[], int, int)
Reads into an array of bytes.
 o readLine(byte[], int, int)
Reads into an array of bytes until all requested bytes have been read or a '\n' is encountered, in which case the '\n' is read into the array as well.
 o resets()
Resets the input stream for a new connection.
 o setContentLength(int)
Sets the content length for this input stream.
 o skip(long)
Skips n bytes of input.

Variables

 o in
 protected InputStream in
The actual input stream for this request.

 o buf
 protected byte buf[]
The input buffer.

 o count
 protected int count
The current number of bytes in the buffer.

 o pos
 protected int pos
The current position in the buffer.

 o total
 protected int total
The total number of bytes for the current request.

 o limit
 protected int limit
The maximum number of bytes for the current request.

 o length
 protected int length
The content length for this request.

Constructors

 o HttpInputStream
 public HttpInputStream(int size)
Creates a new, uninitialized input stream using the specified buffer size.

Parameters:
size - the input buffer size
 o HttpInputStream
 public HttpInputStream()
Creates a new, uninitialized input stream using a default buffer size.

Methods

 o init
 public void init(InputStream in) throws IOException
Initializes the servlet input stream with the specified raw input stream.

Parameters:
in - the raw input stream
 o next
 public void next()
Begins reading the next request.

 o finish
 public void finish() throws IOException
Finishes reading the request without closing the underlying stream.

Throws: IOException
if an I/O error has occurred
 o resets
 public void resets()
Resets the input stream for a new connection.

 o getTotal
 public int getTotal()
Returns the total number of bytes read so far.

 o setContentLength
 public void setContentLength(int len)
Sets the content length for this input stream. This should be called once the headers have been read from the input stream.

Parameters:
len - the content length
 o getContentLength
 public int getContentLength()
Returns the content length for this input stream, or -1 if not set.

 o read
 public int read() throws IOException
Reads a byte of data. This method will block if no input is available.

Returns:
the byte read, or -1 if the end of the stream is reached or the content length has been exceeded
Throws: IOException
if an I/O error has occurred
Overrides:
read in class InputStream
 o read
 public int read(byte b[],
                 int off,
                 int len) throws IOException
Reads into an array of bytes. This method will block until some input is available.

Parameters:
b - the buffer into which the data is read
off - the start offset of the data
len - the maximum number of bytes read
Returns:
the actual number of bytes read, or -1 if the end of the stream is reached or the byte limit has been exceeded
Throws: IOException
if an I/O error has occurred
Overrides:
read in class InputStream
 o readLine
 public int readLine(byte b[],
                     int off,
                     int len) throws IOException
Reads into an array of bytes until all requested bytes have been read or a '\n' is encountered, in which case the '\n' is read into the array as well.

Parameters:
b - the buffer where data is stored
off - the start offset of the data
len - the length of the data
Returns:
the actual number of bytes read, or -1 if the end of the stream is reached or the byte limit has been exceeded
Throws: IOException
if an I/O error has occurred
Overrides:
readLine in class ServletInputStream
 o skip
 public long skip(long n) throws IOException
Skips n bytes of input.

Parameters:
n - the number of bytes to skip
Returns:
the actual number of bytes skipped
Throws: IOException
if an I/O error has occurred
Overrides:
skip in class InputStream
 o available
 public int available() throws IOException
Returns the number of bytes that can be read without blocking.

Returns:
the number of available bytes
Throws: IOException
if an I/O error has occurred
Overrides:
available in class InputStream
 o close
 public void close() throws IOException
Closes the input stream.

Throws: IOException
if an I/O error has occurred
Overrides:
close in class InputStream
 o fill
 protected void fill() throws IOException
Fills input buffer with more bytes.


All Packages  Class Hierarchy  This Package  Previous  Next  Index